#region File Description
//-----------------------------------------------------------------------------
// SpriteFontControl.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using System.Diagnostics;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using SpriteAnimations.Graphics;
using SpriteAnimations.Graphics.Animations;
#endregion

namespace WinFormsGraphicsDevice
{
    /// <summary>
    /// Example control inherits from GraphicsDeviceControl, which allows it to
    /// render using a GraphicsDevice. This control shows how to use ContentManager
    /// inside a WinForms application. It loads a SpriteFont object through the
    /// ContentManager, then uses a SpriteBatch to draw text. The control is not
    /// animated, so it only redraws itself in response to WinForms paint messages.
    /// </summary>
    class SpriteFontControl : GraphicsDeviceControl
    {
        ContentManager content;
        SpriteBatch spriteBatch;
        SpriteFont font;
        Stopwatch timer;

        private Sprite m_Schloss;
        private Sprite xna3waySprite;
        private Sprite test;


        string message = "Hello, World!\n";                     


        /// <summary>
        /// Initializes the control, creating the ContentManager
        /// and using it to load a SpriteFont.
        /// </summary>
        protected override void Initialize()
        {
            content = new ContentManager(Services, "Content");

            spriteBatch = new SpriteBatch(GraphicsDevice);

            m_Schloss = new Sprite(content, new Vector2(1, 325), "schloss");
            m_Schloss.Animations.Add(new CompositeAnimation(new TextureAnimation(1, 2, 230, 174, TimeSpan.FromSeconds(2)),
                new LerpColorAnimation(Color.Gray, Color.BurlyWood, TimeSpan.FromSeconds(15))));

            xna3waySprite = new Sprite(content, new Vector2(110, 500), "farben");
            xna3waySprite.Animations.Add(new CompositeAnimation(new LerpColorAnimation(Color.Red, Color.Yellow, TimeSpan.FromSeconds(6))));

            test = new Sprite(content, new Vector2(400, 10), "ball");
            test.Animations.Add(new CompositeAnimation(new TextureAnimation(2, 4, 30, 30, TimeSpan.FromSeconds(0.4)),
                new BlinkAnimation(TimeSpan.FromSeconds(1)), new PathAnimation(33.0f, new Vector2(93, 456))));

            font = content.Load<SpriteFont>("Arial");


            // Start the animation timer.
            timer = Stopwatch.StartNew();

            // Hook the idle event to constantly redraw our animation.
            Application.Idle += delegate { Invalidate(); };
        }


        /// <summary>
        /// Disposes the control, unloading the ContentManager.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                content.Unload();
            }

            base.Dispose(disposing);
        }


        /// <summary>
        /// Draws the control, using SpriteBatch and SpriteFont.
        /// </summary>
        protected override void Draw()
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // Spin the triangle according to how much time has passed.
            TimeSpan gametime = timer.Elapsed;

            spriteBatch.Begin();
            spriteBatch.DrawString(font, message, new Vector2(23, 50), Color.White);
            m_Schloss.Draw(spriteBatch, gametime);
            xna3waySprite.Draw(spriteBatch, gametime);
            test.Draw(spriteBatch, gametime);
            spriteBatch.End();
        }

        public void SetNewString(string NewString)
        {
            message = NewString;
        }
    }
}
